import { BookType } from 'xlsx';
import { handleBase } from '../DynamicTable/table-base';

export class QuestionBase<T = any> {
  value: any; // 值
  key: string; // 对应后台key值
  asKey: string; // 如果次key存在会替换当前key提交
  label: string; // 说明
  required: boolean; // 是否必填
  disabled: boolean; // 是否禁用
  reg: any; // 正则验证
  prompt: string; // 错误提示
  options: any; // 选项
  order: number; // 排序
  controlType: string; // 控制显示的控件类型
  upload: any; //上传文件
  actions: any; //控制参数
  state: any; //状态集合参数
  type: string; //类型
  layer: any; // 弹出层
  hidden: boolean; //控制隐藏，数据不会提交
  hide: boolean; //隐藏但是数据会提交
  defaultValue: any; //默认值
  placeholder: string; //提示语
  hint: string; //提示
  filter: string; //过滤器
  btnPosition: string; //底部按钮对其方式，默认‘right’
  optionsValue: boolean; //这个是判断options里面有输入的值，提交的时候扩展到外面，{ type | key | typeValue }三个属性
  handle: handleBase;
  maxlength: any;
  isScreen: boolean; //table筛选列
  constructor(
    options: {
      value?: any;
      key?: string;
      label?: string;
      asKey?: string;
      required?: boolean;
      disabled?: boolean;
      reg?: any;
      prompt?: string;
      options?: any;
      order?: number;
      controlType?: string;
      upload?: any;
      actions?: any;
      state?: any;
      type?: string;
      layer?: string;
      hidden?: boolean;
      hide?: boolean;
      defaultValue?: any;
      placeholder?: string;
      hint?: string;
      filter?: string;
      btnPosition?: string;
      optionsValue?: boolean;
      handle?: any;
      maxlength?: any;
      isScreen?: boolean;
    } = {}
  ) {
    this.value = options.value;
    this.key = options.key || '';
    this.asKey = options.asKey || '';
    this.label = options.label || '';
    this.required = !!options.required;
    this.disabled = !!options.disabled;
    this.reg = options.reg || '';
    this.prompt = options.prompt || '';
    this.options = options.options || [];
    this.order = options.order === undefined ? 1 : options.order;
    this.controlType = options.controlType || '';
    this.upload = options.upload || {};
    this.actions = options.actions || {};
    this.state = options.state || {};
    this.type = options.type || '';
    this.layer = options.layer || '';
    this.hidden = !!options.hidden;
    this.hide = !!options.hide;
    this.defaultValue = options.defaultValue || '';
    this.placeholder = options.placeholder || '';
    this.hint = options.hint || '';
    this.filter = options.filter || '';
    this.btnPosition = options.btnPosition || 'right';
    this.optionsValue = options.optionsValue || false;
    this.handle = options.handle || [];
    this.maxlength = options.maxlength || null;
    this.isScreen = options.isScreen || false;
  }
}
export class ConfigBase<T = any> {
  key: string; //判断提交按钮的权限
  id: any; //没有id是提交，有id就是请求
  layout: string; //from布局样式
  name: string; //组件名称
  portType: string; //提交接口类型
  autoSearch: boolean; //自动执行搜索
  searchForm: boolean; //true:不执行请求，false:默认执行请求
  protType: string; //获取接口类型
  noGetDataParams: boolean; //无id货参数也要请求
  idAsName: string; //id的别名
  title: string; //标题
  maskClose: boolean; // 点击蒙层是否允许关闭，true:默认关闭
  style: string; //样式类型
  queryUrl: string; //请求地址
  addUrl: string; //新增地址
  updateUrl: string; //更新地址
  params: Object; //额外参数
  backName: string; //返回地址跳转
  backParams: Object; //返回地址参数
  cancelSave: boolean; //取消所有按钮
  cancelSubmint: boolean; //取消提交按钮
  localSub: boolean; //是否开启拦截到本地
  beforeWithMethod: any; //获取数据拦截
  combinationMethod: any; //提交数据拦截
  type: string; //当config为弹层的时候为layer
  keyId: string; //当config为弹层table时候对应的显示id，目前relateBtn组件用到
  keyName: string; //当config为弹层table时候对应的显示name，目前relateBtn组件用到
  grid: number; //外部分栏默认0
  labelCol: any; //内部分栏
  wrapperCol: any; //内部分栏
  okText: string; //提交按钮文案
  cancelText: string; //取消按钮文案
  isView: boolean; //控制整个表单查看模式
  noPagination: boolean; //不要分页
  data: any; //本地数据
  isPageIndex: boolean; //table分页偏移数量，数量自动取config.data长度
  isPagingLocalData: boolean; //table分页本地数据存储
  dynamicName: string; //from动态字段匹配dynamicFields，dynamicName从哪一个开始添加 （匹配state.name属性）
  constructor(
    options: {
      key?: any;
      id?: any;
      name?: string;
      layout?: string;
      portType?: string;
      autoSearch?: boolean;
      searchForm?: boolean;
      noGetDataParams?: boolean;
      title?: string;
      idAsName?: string;
      style?: string;
      addUrl?: string;
      queryUrl?: string;
      updateUrl?: string;
      params?: Object;
      protType?: string;
      backName?: string;
      backParams?: Object;
      cancelSave?: boolean;
      cancelSubmint?: boolean;
      localSub?: boolean;
      beforeWithMethod?: any;
      combinationMethod?: any;
      type?: string;
      keyId?: string;
      keyName?: string;
      grid?: number;
      labelCol?: any;
      wrapperCol?: any;
      okText?: string; //提交按钮文案
      cancelText?: string; //取消按钮文案
      isView?: boolean;
      noPagination?: boolean; //不要分页
      data?: any; //本地数据
      isPageIndex?: boolean; //table分页偏移数量，数量自动取config.data长度
      isPagingLocalData?: boolean; //table分页本地数据存储
      dynamicName?: string; //table分页本地数据存储
    } = {}
  ) {
    this.key = options.key || '';
    this.title = options.title || '';
    this.name = options.name || '';
    this.layout = options.layout || 'horizontal';
    this.autoSearch = options.autoSearch || false;
    this.searchForm = options.searchForm || false;
    this.noGetDataParams = options.noGetDataParams || false;
    this.portType = options.portType || 'post';
    this.style = options.style || '';
    this.idAsName = options.idAsName || '';
    this.addUrl = options.addUrl || '';
    this.queryUrl = options.queryUrl || '';
    this.updateUrl = options.updateUrl || '';
    this.params = options.queryUrl || {};
    this.protType = options.protType || '';
    this.backName = options.backName || '';
    this.backParams = options.backParams || {};
    this.cancelSave = options.cancelSave || false;
    this.cancelSubmint = options.cancelSubmint || false;
    this.localSub = options.localSub || false;
    this.beforeWithMethod = options.beforeWithMethod || null;
    this.combinationMethod = options.combinationMethod || null;
    this.type = options.type || '';
    this.keyId = options.keyId || '';
    this.keyName = options.keyName || '';
    this.grid = options.grid || 0;
    this.labelCol = options.labelCol || {};
    this.wrapperCol = options.wrapperCol || {};
    this.okText = options.okText || '';
    this.cancelText = options.cancelText || '';
    this.isView = options.isView || false;
    this.noPagination = options.noPagination || false;
    this.data = options.data || null;
    this.isPageIndex = options.isPageIndex || false;
    this.isPagingLocalData = options.isPagingLocalData || false;
    this.dynamicName = options.dynamicName || null;
  }
}
